package com.zf.yichat.api.controller.notice;

import com.zf.yichat.api.controller.BaseController;
import com.zf.yichat.api.dto.request.NoticeViewRequest;
import com.zf.yichat.service.NoticeService;
import com.zf.yichat.utils.response.FsPage;
import com.zf.yichat.utils.response.FsResponse;
import com.zf.yichat.utils.response.FsResponseGen;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 一句话描述功能
 *
 * @author fengsong
 * @date create in 17:55 2020/3/19 2020
 */
@RestController
@RequestMapping("notice")
public class NoticeController extends BaseController {

    @Autowired
    private NoticeService noticeService;

    @PostMapping("/list")
    public FsResponse list(@RequestBody FsPage params) {

        return noticeService.selectList(FsPage.init(params.getPageNo(), params.getPageSize()), getUserId());

    }

    @PostMapping("/list/last")
    public FsResponse listLast(@RequestBody FsPage params) {

        return noticeService.selectListLast(  getUserId());

    }

    @PostMapping("/unview/count")
    public FsResponse unviewCount() {

        return FsResponseGen.successData(noticeService.unviewCount(getUserId()));

    }

    @PostMapping("/view")
    public FsResponse view(@RequestBody NoticeViewRequest params) {

        noticeService.view(params.getNoticeId(), getUserId());

        return FsResponseGen.success();

    }
}
